define(function (require, exports, module) {
    require('./css/style.css')

    function onload() {
        return {
            template: require('./Widget.html'),
            name: 'SearchInput',
            props: {
                // value 字段显示标签
                // param 字段属性名
                selects: {
                    type: Array,
                    default: () => {
                        return []
                    },
                    required: false
                }
            },
            data() {
                return {
                    selectValue: '',
                    inputObj: {
                        value: '',
                        param: ''
                    },
                    // 是否选择提示，选择提示后才能查询
                    isSelectTip: false
                }
            },
            mounted() {
            },
            methods: {
                doSelect() {
                    if (this.inputObj.value) {
                        this.$emit('querySearch', { value: this.selectValue, param: this.inputObj.param, content: this.inputObj.value })
                    }
                },
                clearTipStatus() {
                    this.isSelectTip = false
                },
                clearInput() {
                    this.inputObj = {
                        value: '',
                        param: ''
                    }
                },
                querySearch(queryString, cb) {
                    const data = []
                    if (queryString) {
                        this.selects.forEach(item => {
                            data.push({
                                value: item.value + ': ' + queryString,
                                param: item.param
                            })
                        })
                    }
                    cb(data)
                },
                // 发送检索事件
                handleSelect(item) {
                    this.isSelectTip = true
                    const selectValue = this.selects.find(o => o.param === item.param).value
                    this.selectValue = selectValue
                    this.inputObj.value = item.value.substring(selectValue.length + 2)
                    this.inputObj.param = item.param
                    this.$emit('querySearch', { value: this.selectValue, param: this.inputObj.param, content: this.inputObj.value })
                }
            }
        }
    }

    module.exports = {
        onload
    };
});
